package promote.brozen.spring.event;

import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import promote.brozen.utils.concurrent.Threads;

/**
 * @author Brozen
 * @date 2020/9/1 8:30 AM
 * @email brozen@qq.com
 */
@Component
public class EventSource implements ApplicationEventPublisherAware, InitializingBean {

    @Setter
    private ApplicationEventPublisher applicationEventPublisher;


    @Override
    public void afterPropertiesSet() throws Exception {
        new Thread(() -> {
            Threads.silentSleep(1000L);
            System.out.println(String.format("publish at %s", Thread.currentThread().getName()));
            applicationEventPublisher.publishEvent(new MyEvent(EventSource.this));
        }).start();
    }

}
